steer = {
    _sig = nil,
    _min = -45,
    _max = 45,
    _ang = 0
}

function steer.run()
    if ( steer._ang < 0 ) then
        print("Steer pin:"..steer._sig.." left:"..(0-steer._ang))
    elseif ( steer._ang > 0 ) then
        print("Steer pin:"..steer._sig.." right:"..(steer._ang))
    else
        print("Stter pin:"..steer._sig.." 0")
    end
    local duty = ((steer._ang+90)/180 +1) * 51.2
    print("duty:"..duty)
    pwm.setduty(steer._sig, duty)
    pwm.start(steer._sig)
    pwm.stop(steer._sig)
end

function steer.bind(sig)
    steer._sig = sig
    steer._ang = 0
    pwm.setup(steer._sig, 50, 76.8)
    steer.run()
end

function steer.getAngle()
    return steer._ang
end

function steer.setAngle(angle)
    if ( angle < steer._min ) then
        steer._ang = steer._min
    elseif ( angle > steer._max ) then
        steer._ang = steer._max
    else
        steer._ang = angle
    end
    steer.run()
end
